package chapter;

public class CountString {
	     String a;
	     String b;

	        public CountString(String a, String b) {
	            this.a = a;
	            this.b = b;
	        }

	      
	        public int countOccurrences() {
	           
	            if (a == null || b == null || b.isEmpty() || b.length() > a.length()) {
	                return 0;
	            }

	            int count = 0; 
	            int lastIndex = 0; 

	            
	            while ((lastIndex = a.indexOf(b, lastIndex)) != -1) {
	               
	                count++;

	               
	                lastIndex += b.length();
	            }
	            
	          
	            return count;
	        }
	    }

